package com.linkage.educloud.ah.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.linkage.educloud.ah.R;
import com.linkage.educloud.ah.bean.CommonResBean;
import com.linkage.educloud.ah.util.ImageLoader;

import java.util.List;

/**
 * Created by Mr'Tang on 2018/12/12.
 */

public class WatchedAdapter extends android.widget.BaseAdapter {
    private Context mContext;
    private List<CommonResBean> mList;

    public WatchedAdapter(Context context, List<CommonResBean> list) {
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public CommonResBean getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_watched, null);
            viewHolder = new ViewHolder();
            viewHolder.item_watched_img = convertView.findViewById(R.id.item_watched_img);
            viewHolder.item_watched_name = convertView.findViewById(R.id.item_watched_name);
            viewHolder.item_watched_title = convertView.findViewById(R.id.item_watched_title);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        final CommonResBean bean = getItem(position);
        ImageLoader.loadImg(mContext, bean.getPic_path(), viewHolder.item_watched_img);
        viewHolder.item_watched_name.setText("主讲人：" + bean.getAuthor());
        viewHolder.item_watched_title.setText(bean.getTitle());
        return convertView;
    }

    private class ViewHolder {
        ImageView item_watched_img;
        TextView item_watched_name;
        TextView item_watched_title;
    }
}